﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_CancelPostil_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_CancelPostil_V2];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_CancelPostil_V2]
    @DocID int
AS
BEGIN
SET NOCOUNT ON;

-- Remove the latest postil for the given document
WITH T AS
(
    SELECT TOP 1 *
        FROM dbo.UDS_Flow_Postil
        WHERE Doc_ID = @DocID
        ORDER BY Postil_Date DESC
)
DELETE FROM T;

END
GO
